package com.ruoyi.quotation.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.quotation.domain.QuoEngineering;
import com.ruoyi.quotation.service.IQuoEngineeringService;
import com.ruoyi.quotation.vo.QuoteEngineeringVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 工程审核信息Controller
 */
@RestController
@RequestMapping("/quotation/engineering")
public class QuoEngineeringController extends BaseController {

    @Autowired
    private IQuoEngineeringService quoEngineeringService;

    /**
     * 查询工程审核列表
     */
    @PreAuthorize("@ss.hasPermi('quotation:engineering:list')")
    @GetMapping("/list")
    public TableDataInfo list(QuoEngineering quoEngineering) {
        startPage();
        List<QuoteEngineeringVO> list = quoEngineeringService.selectQuoEngineeringList(quoEngineering);
        return getDataTable(list);
    }

    /**
     * 导出工程审核列表
     */
    @PreAuthorize("@ss.hasPermi('quotation:engineering:export')")
    @Log(title = "工程审核", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, QuoEngineering quoEngineering) {
        List<QuoteEngineeringVO> list = quoEngineeringService.selectQuoEngineeringList(quoEngineering);
        ExcelUtil<QuoteEngineeringVO> util = new ExcelUtil<>(QuoteEngineeringVO.class);
        util.exportExcel(response, list, "工程审核数据");
    }

    /**
     * 获取工程审核详细信息
     */
    @PreAuthorize("@ss.hasPermi('quotation:engineering:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id) {
        return success(quoEngineeringService.selectQuoEngineeringById(id));
    }

    /**
     * 新增工程审核
     */
    @PreAuthorize("@ss.hasPermi('quotation:engineering:add')")
    @Log(title = "工程审核", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody QuoEngineering quoEngineering) {
        return toAjax(quoEngineeringService.insertQuoEngineering(quoEngineering));
    }

    /**
     * 修改工程审核
     */
    @PreAuthorize("@ss.hasPermi('quotation:engineering:edit')")
    @Log(title = "工程审核", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody QuoEngineering quoEngineering) {
        return toAjax(quoEngineeringService.updateQuoEngineering(quoEngineering));
    }

    /**
     * 删除工程审核
     */
    @PreAuthorize("@ss.hasPermi('quotation:engineering:remove')")
    @Log(title = "工程审核", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids) {
        return toAjax(quoEngineeringService.deleteQuoEngineeringByIds(ids));
    }
    
    /**
     * 执行工程审核
     */
    @PreAuthorize("@ss.hasPermi('quotation:engineering:audit')")
    @Log(title = "工程审核", businessType = BusinessType.UPDATE)
    @PostMapping("/audit")
    public AjaxResult audit(@RequestBody QuoEngineering quoEngineering) {
        return toAjax(quoEngineeringService.auditEngineering(quoEngineering));
    }
} 